{% load humanize %}
{% load staticfiles %}
<!DOCTYPE html>
<html lang="en">

<head>

    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta name="description" content="">
    <meta name="author" content="">

    <title>MalSpider - Dashboard</title>

    <!-- Bootstrap Core CSS -->
    <link href="{% static "bower_components/bootstrap/dist/css/bootstrap.min.css" %}" rel="stylesheet">

    <!-- MetisMenu CSS -->
    <link href="{% static "bower_components/metisMenu/dist/metisMenu.min.css" %}" rel="stylesheet">
    
    <!-- Custom CSS -->
    <link href="{% static "dist/css/sb-admin-2.css" %}" rel="stylesheet">

   <link href="{% static "bower_components/datatables-plugins/integration/bootstrap/3/dataTables.bootstrap.css" %}" rel="stylesheet">

    <!-- DataTables Responsive CSS -->
    <link href="{% static "bower_components/datatables-responsive/css/responsive.dataTables.css" %}" rel="stylesheet">

    <!-- Custom Fonts -->
    <link href="{% static "bower_components/font-awesome/css/font-awesome.min.css" %}" rel="stylesheet" type="text/css">

    <!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
    <!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
    <!--[if lt IE 9]>
        <script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
        <script src="https://oss.maxcdn.com/libs/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->

    <!-- jQuery -->
    <script src="{% static "bower_components/jquery/dist/jquery.min.js" %}"></script>
    <script>
    $(document).ready(function() {
        $('#dataTables-example').DataTable({
                responsive: true
        });
    });
    </script>

    <!-- Bootstrap Core JavaScript -->
    <script src="{% static "bower_components/bootstrap/dist/js/bootstrap.min.js" %}"></script>

    <!-- Metis Menu Plugin JavaScript -->
    <script src="{% static "bower_components/metisMenu/dist/metisMenu.min.js" %}"></script>

    <!-- Morris Charts JavaScript -->
    <script src="{% static "bower_components/raphael/raphael-min.js" %}"></script>
    <script src="{% static "bower_components/morrisjs/morris.min.js" %}"></script>
    <script src="{% static "js/morris-data.js" %}"></script>

    <!-- DataTables JavaScript -->
    <script src="{% static "bower_components/datatables/media/js/jquery.dataTables.min.js" %}"></script>
    <script src="{% static "bower_components/datatables-plugins/integration/bootstrap/3/dataTables.bootstrap.min.js" %}"></script>

    <!-- Custom Theme JavaScript -->
    <script src="{% static "dist/js/sb-admin-2.js" %}"></script>

</head>
<body>

    <div id="wrapper">

        <!-- Navigation -->
        <nav class="navbar navbar-default navbar-static-top" role="navigation" style="margin-bottom: 0">
            <div class="navbar-header">
                <button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
                    <span class="sr-only">Toggle navigation</span>
                    <span class="icon-bar"></span>
                    <span class="icon-bar"></span>
                    <span class="icon-bar"></span>
                </button>
                <a class="navbar-brand" href="index.html">MalSpider</a>
            </div>
            <!-- /.navbar-header -->

            <div class="navbar-default sidebar" role="navigation">
                <div class="sidebar-nav navbar-collapse">
                    <ul class="nav" id="side-menu">
                        <li>
                            <a href="/"><i class="fa fa-dashboard fa-fw"></i> Dashboard</a>
                        </li>
			<li>
                            <a href="/admin"><i class="fa fa-wrench fa-fw"></i>Admin Panel</a>
                        </li>
                        <li>
                            <a href="/daemon"><i class="fa fa-gears fa-fw"></i>Spider Daemon</a>
                        </li>
                        <li>
                            <a href="#"><i class="fa fa-bell fa-fw"></i>View Alerts<span class="fa arrow"></span></a>
                            <ul class="nav nav-second-level">
                                <li>
                                    <a href="/alerts/last_24_hours/">Last 24 Hours</a>
                                </li>
                                <li>
                                    <a href="/alerts/last_3_days/">Last 3 Days</a>
                                </li>
                                <li>
                                    <a href="/alerts/last_7_days/">Last 7 Days</a>
                                </li>
                                <li>
                                    <a href="/alerts/last_30_days/">Last 30 Days</a>
                                </li>
                                <li>
                                    <a href="/alerts/last_90_days/"> Last 90 Days</a>
                                </li>
                                <li>
                                    <a href="/alerts/all_time/">All Time</a>
                                </li>
                            </ul>
                            <!-- /.nav-second-level -->
                        </li>
                        <li>
                           {% if user.is_authenticated %}
                                <a href="/logout"><i class="fa fa-sign-out fa-fw"></i>Logout</a>
                           {% endif %}
                        </li>
                    </ul>
                </div>
                <!-- /.sidebar-collapse -->
            </div>
            <!-- /.navbar-static-side -->
        </nav>

        <div id="page-wrapper">
        {% if jobid %}
            <div class="row">
               <div class="col-log-12 alert alert-success">
                   Scanning {{ scan_domain }}. <br/>
                   Daemon job id: <a href="/daemon/{{ jobid }}">{{jobid}}</a><br/>
               </div>
	    </div>
        {% elif error %}
            <div class="row">
               <div class="col-log-12 alert alert-danger">
                   {{ error }}
               </div>
	    </div>
        {% endif %}

            <div class="row">
                <div class="col-lg-12">
                    <h1 class="page-header">Dashboard</h1>
                </div>
                <!-- /.col-lg-12 -->
            </div>
            <!-- /.row -->
            <div class="row">
                <div class="col-lg-3 col-md-6">
                    <div class="panel panel-red">
                        <div class="panel-heading">
                            <div class="row">
                                <div class="col-xs-3">
                                    <i class="fa fa-bell fa-5x"></i>
                                </div>
                                <div class="col-xs-9 text-right">
                                    <div class="huge">{{unique_alerts|intcomma}}</div>
                                    <div>Security Alerts</div>
                                </div>
                            </div>
                        </div>
                        <a href="/alerts/last_24_hours/">
                            <div class="panel-footer">
                                <span class="pull-left">View Alerts</span>
                                <span class="pull-right"><i class="fa fa-arrow-circle-right"></i></span>
                                <div class="clearfix"></div>
                            </div>
                        </a>
                    </div>
                </div>
                <div class="col-lg-3 col-md-6">
                    <div class="panel panel-green">
                        <div class="panel-heading">
                            <div class="row">
                                <div class="col-xs-3">
                                    <i class="fa fa-eye fa-5x"></i>
                                </div>
                                <div class="col-xs-9 text-right">
                                    <div class="huge">{{all_orgs|length}}</div>
                                    <div>Monitored Domains</div>
                                </div>
                            </div>
                        </div>
                        <a href="/alerts/last_24_hours/">
                            <div class="panel-footer">
                                <span class="pull-left">View Alerts</span>
                                <span class="pull-right"><i class="fa fa-arrow-circle-right"></i></span>
                                <div class="clearfix"></div>
                            </div>
                        </a>
                    </div>
                </div>
                <div class="col-lg-3 col-md-6">
                    <div class="panel panel-yellow">
                        <div class="panel-heading">
                            <div class="row">
                                <div class="col-xs-3">
                                    <i class="fa fa-bug fa-5x"></i>
                                </div>
                                <div class="col-xs-9 text-right">
                                    <div class="huge">{{pages_count|intcomma}}</div>
                                    <div>Pages Crawled</div>
                                </div>
                            </div>
                        </div>
                        <a href="/alerts/last_24_hours/">
                            <div class="panel-footer">
                                <span class="pull-left">View Alerts</span>
                                <span class="pull-right"><i class="fa fa-arrow-circle-right"></i></span>
                                <div class="clearfix"></div>
                            </div>
                        </a>
                    </div>
                </div>
                <div class="col-lg-3 col-md-6">
                    <div class="panel panel-primary">
                        <div class="panel-heading">
                            <div class="row">
                                <div class="col-xs-3">
                                    <i class="fa fa-search fa-5x"></i>
                                </div>
                                <div class="col-xs-9 text-right">
                                    <div class="huge">{{elems_count|intcomma}}</div>
                                    <div>Elements Analyzed</div>
                                </div>
                            </div>
                        </div>
                        <a href="/alerts/last_24_hours/">
                            <div class="panel-footer">
                                <span class="pull-left">View Alerts</span>
                                <span class="pull-right"><i class="fa fa-arrow-circle-right"></i></span>
                                <div class="clearfix"></div>
                            </div>
                        </a>
                    </div>
                </div>
            </div>
            <!-- /.row -->

            <div class="row">
		<div class="col-lg-9">
                    <div class="panel panel-default">
                        <div class="panel-heading">
                            Monitored Domains
                        </div>
                        <!-- /.panel-heading -->
                        <div class="panel-body">
                            <div class="dataTable_wrapper">
                                <table class="table table-striped table-bordered table-hover" id="dataTables-example">
                                    <thead>
                                        <tr>
                                            <th>Organization</th>
                                            <th>Category</th>
                                            <th>Domain</th>
					    <th>Adhoc Scan</th>
                                        </tr>
                                    </thead>
                                    <tbody>
		    		{% for org in all_orgs %}
					<tr><td>{{ org.org_name }}</td><td>{{org.category}}</td><td><a href="/org/{{org.id}}">{{org.domain}}</a></td><td align="center"><div class="btn-group"><form action="/scan/{{org.id}}"><button class="btn btn-success btn-sm" role="link" type="submit">Scan</button></form></td></tr>
		    		{% endfor %}
				    </tbody>
				</table>
			    </div>
			</div>
		    </div>
		</div>
                <div class="col-lg-3">
                    <div class="panel panel-default">
                        <div class="panel-heading">
                            <i class="fa fa-bell fa-fw"></i> Web Crawler Status
                        </div>
                        <!-- /.panel-heading -->
                        <div class="panel-body">
                            <div class="list-group">
				{% if not scrapyd_connected %}
					<div class="alert alert-danger">
					Crawler daemon is not running or unable to locate project!
					</div>
				{% endif %}
                                <a href="#" class="list-group-item">
                                    <i class="fa fa-play fa-fw"></i> Running Jobs
                                    <span class="pull-right text-muted small"><em>{{running_jobs|intcomma}}</em>
                                    </span>
                                </a>
                                <a href="#" class="list-group-item">
                                    <i class="fa fa-pause fa-fw"></i> Pending Jobs
                                    <span class="pull-right text-muted small"><em>{{pending_jobs|intcomma}}</em>
                                    </span>
                                </a>
                                <a href="#" class="list-group-item">
                                    <i class="fa fa-check fa-fw"></i> Finished Jobs
                                    <span class="pull-right text-muted small"><em>{{finished_jobs|intcomma}}</em>
                                    </span>
                                </a>
                            </div>
                            <!-- /.list-group -->
                            <a href="/daemon" class="btn btn-default btn-block">View Daemon</a>
                        </div>
                        <!-- /.panel-body -->
                    </div>
                    <!-- /.panel -->
                </div>
                <!-- /.col-lg-4 -->
		<div class="col-lg-3">
                    <div class="panel panel-default">
                        <div class="panel-heading">
                            <i class="fa fa-bell fa-fw"></i> Top 5 Alert Reasons
                        </div>
                        <!-- /.panel-heading -->
                        <div class="panel-body">
                            <div class="list-group">
				{%for item in alert_count_by_reason %}
					<li class="list-group-item text-danger">
					<b>{{forloop.counter}}.</b> {{item.reason}}
					</li>
				{% endfor %}
                            </div>
                            <!-- /.list-group -->
                            <a href="/alerts/all_time/" class="btn btn-default btn-block">View All Alerts</a>
                        </div>
                        <!-- /.panel-body -->
                    </div>
                    <!-- /.panel -->
                </div>
                <!-- /.col-lg-4 -->

            </div>
            <!-- /.row -->
        </div>
        <!-- /#page-wrapper -->

    </div>
    <!-- /#wrapper -->
</body>

</html>
